<?php

namespace services\patient;

use Yii;
use common\components\Service;
use common\models\patient\BodyParts;

/**
 * Class BodyPartsService
 * @package services\patient
 */
class BodyPartsService extends Service
{
    /**
     * 根据ID查找信息
     *
     * @param int $id
     * @return BodyParts|null
     */
    public function findById(int $id = 0): ?BodyParts
    {
        return BodyParts::find()->where(['id' => $id])->one();
    }

    /**
     * 查找信息
     *
     * @param array $condition
     * @return BodyParts|null
     */
    public function findInfo(array $condition = []): ?BodyParts
    {
        $query = BodyParts::find();

        isset($condition['patient_user_id']) && $query->andWhere(['patient_user_id' => $condition['patient_user_id']]);
        isset($condition['body_parts_id']) && $query->andWhere(['body_parts_id' => $condition['body_parts_id']]);

        return $query->one();
    }

    /**
     * 查找列表
     *
     * @param array $condition
     * @return array|\yii\db\ActiveRecord[]
     */
    public function findList(array $condition = [])
    {
        $query = BodyParts::find();

        isset($condition['patient_user_id']) && $query->andWhere(['patient_user_id' => $condition['patient_user_id']]);
        isset($condition['body_parts_id']) && $query->andWhere(['body_parts_id' => $condition['body_parts_id']]);
        isset($condition['status']) && $query->andWhere(['status' => $condition['status']]);

        return $query->asArray()->all();
    }

}